<!DOCTYPE html>
<html>

<head>
    <title>八厂</title>
    <meta charset="UTF-8">
    <link rel="shortcut icon" href="custom/images/favicon.ico?v=2" />
    <style>
        html,
        body {
            padding: 0px;
            margin: 0px;
        }
    </style>
    <script src='../libs/jquery-3.4.1.min.js'></script>
    <script src='../libs/message.js'></script>
    <script src='../custom/configs/htconfig.js'></script>
    <script src='../custom/libs/echarts.js'></script>
    <script src='../libs/core/ht.js'></script>
    <script src='../libs/plugin/ht-edgetype.js'></script>
    <script src='../libs/plugin/ht-obj.js'></script>
    <script src='../libs/core/ht-ui.js'></script>
    <script src='../libs/plugin/ht-vector.js'></script>
    <script src="../conf/confURL.js"></script>
    <script src='../conf/dateTime.js'></script>
    <script src='../libs/plugin/ht-cssanimation.js'></script>
    <script src="../libs/plugin/ht-autolayout.js"></script>
    <script src='../libs/plugin/ht-dialog.js'></script>
    <script>
        let frame;
        var H = [];
        let table;
        dataModel = new ht.DataModel();
        graphView = new ht.graph.GraphView(dataModel);
        //获取url
        var url = domain + "/HT_DATA_EIGHT.getGlobalStatistics.do"
        function init() {
            //获取图纸
            graphView.addToDOM();
            ht.Default.xhrLoad('displays/智慧兴达/兴达八厂/生产监控/product_eightFactory.json', function (text) {
                var json = ht.Default.parse(text);
                if (json.title) document.title = json.title;
                dataModel.deserialize(json);
                graphView.fitContent(true);
                tag()
                getData1()
                getData2()
                getData3()
                getData4()
                getData5()
                getData6()
                openInterval()
                //时间刷新
                setInterval(function () {
                    let dateTime = dataModel.getDataByTag('time');
                    let time = updateTime();
                    dateTime.a('time', time);
                }, 1000);
                //更新数据
                setInterval(function () { getData1() }, 1000 * 10);
                setInterval(function () { getData2() }, 1000 * 60 * 5);
                setInterval(function () { getData4() }, 1000 * 60 * 30);
            });
        }
        //获取标签
        function tag() {
            for (let i = 1; i < 5; i++) {
                H.push(dataModel.getDataByTag("H" + i))
            }
            table = dataModel.getDataByTag("table")
        }
        //电镀报警信息接口
        function getData1() {
            const warn1 = dataModel.getDataByTag('warn1')
            const alarm = dataModel.getDataByTag('alarm')
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_FC_REPORT_DDBJXXTJ"
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',    //application/json
                success: function (res) {
                    var repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.HT_SC_FC_REPORT_DDBJXXTJ.visible == "true") {
                        warn1.s("2d.visible", false)
                        alarm.s("2d.visible", true)
                        H[0].s("text", repData.HT_SC_FC_REPORT_DDBJXXTJ.title)
                        alarm.a("colData", repData.HT_SC_FC_REPORT_DDBJXXTJ.data)
                    } else {
                        warn1.s("2d.visible", true)
                        alarm.s("2d.visible", false)
                    }
                },
                error: function (error) {
                    //console.log('err');
                    warn1.s("2d.visible", true)
                    alarm.s("2d.visible", false)
                }
            });
        }
        //工序维修费用统计接口
        function getData2() {
            const warn2 = dataModel.getDataByTag('warn2')
            const diedai = dataModel.getDataByTag('diedai')
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_FC_REPORT_GXWXFYTJ"
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    var repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.HT_SC_FC_REPORT_GXWXFYTJ.visible == "true") {
                        warn2.s("2d.visible", false)
                        diedai.s("2d.visible", true)
                        H[1].a("title", repData.HT_SC_FC_REPORT_GXWXFYTJ.title)
                        diedai.a("dataSource", repData.HT_SC_FC_REPORT_GXWXFYTJ.data)
                    } else {
                        warn2.s("2d.visible", true)
                        diedai.s("2d.visible", false)
                    }
                },
                error: function (error) {
                    // console.log('err');
                    warn2.s("2d.visible", true)
                    diedai.s("2d.visible", false)
                }
            });
        }
        //机床状态统计接口
        function getData3() {
            const jichuang = dataModel.getDataByTag("jichuang")
            const warn3 = dataModel.getDataByTag('warn3')
            const table1 = dataModel.getDataByTag('table1')
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_FC_REPORT_JCZTTJ"
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    var repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.HT_SC_FC_REPORT_JCZTTJ.visible == "true") {
                        warn3.s("2d.visible", false)
                        jichuang.s("2d.visible", true)
                        table1.s("2d.visible", true)
                        H[3].a("title", repData.HT_SC_FC_REPORT_JCZTTJ.title)
                        table.a("ht.dataSource", repData.HT_SC_FC_REPORT_JCZTTJ.data)
                        table1.a("ht.dataSource", repData.HT_SC_FC_REPORT_JCZTTJ.total)
                    } else {
                        warn3.s("2d.visible", true)
                        jichuang.s("2d.visible", false)
                        table1.s("2d.visible", false)
                    }
                },
                error: function (error) {
                    //console.log('err');
                    warn3.s("2d.visible", true)
                    jichuang.s("2d.visible", false)
                    table1.s("2d.visible", false)
                }
            });
        }
        //车间用电统计接口
        function getData4() {
            const warn4 = dataModel.getDataByTag('warn4')
            const chart = dataModel.getDataByTag('chart') //车间 
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_FC_REPORT_CJYDTJ"
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    var repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.HT_SC_FC_REPORT_CJYDTJ.visible == "true") {
                        warn4.s("2d.visible", false)
                        chart.s("2d.visible", true)
                        H[2].a("title", repData.HT_SC_FC_REPORT_CJYDTJ.title)
                        chart.a("xAxis", repData.HT_SC_FC_REPORT_CJYDTJ.data.month)
                        chart.a("yAxis3", repData.HT_SC_FC_REPORT_CJYDTJ.data.workshop1)
                        chart.a("yAxis1", repData.HT_SC_FC_REPORT_CJYDTJ.data.workshop2)
                        chart.a("yAxis2", repData.HT_SC_FC_REPORT_CJYDTJ.data.workshop3)
                    } else {
                        warn4.s("2d.visible", true)
                        chart.s("2d.visible", false)
                    }
                },
                error: function (error) {
                    //console.log('err');
                    warn4.s("2d.visible", true)
                    chart.s("2d.visible", false)
                }
            });
        }
        //返回按钮
        function getData5() {
            const backButton = dataModel.getDataByTag("backButton")
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_FC_BUTTON_RETURN"
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    var repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.HT_SC_FC_BUTTON_RETURN.visible == "true") {
                        backButton.a("url", repData.HT_SC_FC_BUTTON_RETURN.data.url)
                        backButton.s("2d.visible", repData.HT_SC_FC_BUTTON_RETURN.visible)
                    }
                },
                error: function (error) {
                    // console.log('err');
                }
            });
        }
        //中间3车间
        function getData6() {
            const work1 = dataModel.getDataByTag("work1")
            const work2 = dataModel.getDataByTag("work2")
            const work3 = dataModel.getDataByTag("work3")
            var repData = {};
            $.ajax({
                type: "POST",
                url: url,
                data: {
                    props: "HT_SC_ZZ_FC_MAP"
                },
                headers: request_headers,
                async: true,
                contentType: 'application/x-www-form-urlencoded',
                success: function (res) {
                    var repData = JSON.parse(res);
                    if (repData._MSG_ === 'OK' && repData.HT_SC_ZZ_FC_MAP.visible == "true") {
                        work1.s("label", repData.HT_SC_ZZ_FC_MAP.urlMap)
                        work2.s("label", repData.HT_SC_ZZ_FC_MAP.urlMap)
                        work3.s("label", repData.HT_SC_ZZ_FC_MAP.urlMap)
                    }
                },
                error: function (error) {
                    // console.log('err');
                }
            });
        }
        //表格自动滚动
        function tableRun() {
            let tabledata = table.a("ht.dataSource");
            var old = table.a('ht.translateY');
            table.a('ht.translateY', old - 45);
            tabledata.push(tabledata[0]);
            tabledata.splice(0, 1)
            table.a("ht.dataSource", tabledata);
            table.a('ht.translateY', old);
        }
        //重新打开定时器，播放滚动
        function openInterval() {
            tableTimer = setInterval(tableRun, 2000);
        }
        // 报表弹出框
        function showDialog(url) {
            setDialogConfig(url) 
        }
    </script>
</head>

<body onload='setTimeout(init, 300)'>
</body>

</html>